package code.class3.easy;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * https://leetcode.cn/problems/number-of-distinct-averages/
 * 不同的平均值数目
 */
public class Code05_distinctAverages {
    public static void main(String[] args) {
        int[] arr = {4, 1, 4, 0, 3, 5};
        int res = distinctAverages(arr);
        System.out.println("res = " + res);
    }

    public static int distinctAverages(int[] arr) {
        Arrays.sort(arr);
        int p1 = 0, p2 = arr.length - 1;
        Set<Integer> ans = new HashSet<>();
        while (p1 < p2) {
            ans.add(arr[p1++] + arr[p2--]);
        }
        return ans.size();
    }
}

